#include<iostream>
#include<string>
using std::endl;
using std::cout;
using std::string;

class A
{
public:
    int a = 10;
};
class B
:public A
{
public:
    int b = 20;
};
int main(void){
    A atest; //基类
    B btest; //派生类
    //A *preA = &btest;//合法的
    //B *preBtest = &btest; //son 
    //B *preB = static_cast<B*>(preA); 
    A*preA = &atest;
    //只能用dynamic_cast 因为会有类型检查
    B *preB = static_cast<B*>(preA);//父转子
    if(preB){
        cout<<preB->b<<endl;
    }else{
        cout<<"转换失败"<<endl;
    }
    //cout<<preB->b<<endl;
    
}